let loginModule = (function(){
    let $userName = $(".userName"),
        $userPass = $(".userPass"),
        $submit = $(".submit");
    
    function handle(){
        $submit.click(function() {
            let userName = $userName.val().trim(),
                userPass = $userPass.val().trim();
            //输入的用户名密码不能为空
            if(userName === "" || userPass === ""){
                alert('用户名密码不能为空，请您重新输入');
                return;
            }
            //输入的密码要进行MD5加密，加密后为32位的字符串
            userPass = md5(userPass);
            //发送AJAX请求
            axios.post('/user/login',{
                account:userName,
                password:userPass
            }).then(result=>{
                let {
                    code,
                    codeText,
                    power
                } = result;
                if(parseFloat(code) === 0){
                    //登陆成功
                    alert('登陆成功');
                    localStorage.setItem('power',encodeURIComponent(power))  //存储权限
                    window.location.href = 'index.html';
                    return;
                }
                alert('账号密码输入错误，请重新输入')
            })

        })

    }
    return {
        init(){
            handle()
        }
    }
})();
loginModule.init();